﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AFCEPF.Samples.WebSamples.Concepts
{
    public partial class View_QueryStringReceiver : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Count != 0)
            {
                fillControlsWithQueryStringValues();

                iterateQueryString();
            }


        }

        /// <summary>
        /// Fills the TextBoxes contents with values obtained from the QueryString.
        /// </summary>
        private void fillControlsWithQueryStringValues()
        {
            // Récupération des valeurs du QueryString par le nom du paramètre (sa clé dans la collection).
            lblNameViaNamedParam.Text = "Name : " + Request.QueryString["Name"];
            lblFirstNameViaNamedParam.Text = "FirstName : " + Request.QueryString["FirstName"];

            // Récupération des valeurs du QueryString par l'index du paramètre (son index dans la Collection).
            lblNameViaOrdinalPosition.Text = "Name : " + Request.QueryString[0];
            lblFirstNameViaOrdinalPosition.Text = "FirstName : " + Request.QueryString[1];
            
        }

        private void iterateQueryString()
        {
            StringBuilder sb = new StringBuilder(); 

            foreach (string s in Request.QueryString)
            {
                sb.AppendFormat("{0}\r\n",Request.QueryString[s]);
            }

            lblQueryStringDump.Text = sb.ToString();
            
        }


    }
}